<style>


</style>
<div id='main-frbMessage-main'>
	<div id='main-frbMessage-main-title''>Messages 
	<span id='pagination'>
		<a href='<?php echo $data['baseurl']; ?>admin/frbMessage/frbMessage_MainController/index?page=<?php echo $data['previous_page']; ?>' title='Précédent'>&lt</a>
		Page <?php echo $data['page']; ?> / <?php echo $data['total']; ?>
		<a href='<?php echo $data['baseurl']; ?>admin/frbMessage/frbMessage_MainController/index?page=<?php echo $data['next_page']; ?>' title='Suivant'>&gt</a>
	</span>
	</div>
	<div id='main-frbMessage-main-inbox'>
		<table>
			<tr id='table-title'>
			<th> Date </th>  <th> Expéditeur </th> <th> Message </th>
			</tr>
			<?php foreach($data['mailInbox'] as $k1=>$v1): ?>
			<tr id='<?php echo $v1->mes_id; ?>' class='click-to-view new-message-eq-<?php echo $v1->mes_flag; ?>'>
				<td><?php echo $v1->mes_date; ?></td>  <td><?php echo $v1->mes_nom; ?></td>  <td class='text-shrink'><?php echo $v1->mes_mes; ?></td>
				<input type='hidden' name ='id' value='<?php echo $v1->mes_id; ?>'>
				<input type='hidden' name ='mail' value='<?php echo $v1->mes_mail; ?>'>
				<input type='hidden' name ='tel' value='<?php echo $v1->mes_tel; ?>'>
			</tr>
			<?php endforeach; ?>
		</table>
	</div>
	<div id='main-frbMessage-message'>
		<div id='main-frbMessage-message-from'></div>		
		<div id='main-frbMessage-message-tel'></div>
		<div id='main-frbMessage-message-date'></div>
		<div id="main-frrMessage-toolbox">
			<input type="hidden" id='tb-mail-to-answer' value=''>
			<input type="hidden" id='tb-id' value=''>
			<input type="button" value="Répondre" class="personal-button" id='answer'>
			<input type="button" value="Supprimer" class="personal-button" id='delete-mess'>
		</div>
		<div id='main-frbMessage-message-content'>Message : <p></p> </div>
	</div>
</div>

<script type="text/javascript">
$(document).ready(function(){
	$('#main-frbMessage-message').hide();
	$("#answer").click(function(){
		var mail = $("#tb-mail-to-answer").attr('value');
		window.location.href = "mailto:"+mail+"?subject=[marseille-appart.fr] Réponse demande d'informations&body=Bonjour,";
	});

	$("#delete-mess").click(function(){
		if(!confirm("Êtes-vous sûr de vouloir supprimer ce message ?")) return;
		var id_mss = $("#tb-id").attr("value");
		$.ajax({
			type : 'POST',
			url: "<?php echo $data['baseurl']; ?>admin/frbMessage/frbMessage_MainController/index",
			cache: false,
			data: "action=del&id="+id_mss,
			success: function(html){
				$("#"+id_mss).hide();
				$('#main-frbMessage-message').fadeOut('slow')
			}
		});
		;
	});
	
	$(".click-to-view").click(function(){
		var tr = $(this)
		$('#main-frbMessage-message').fadeOut('slow', function(){
			var date = tr.children('td:eq(0)').html();
			var from = tr.children('td:eq(1)').html();
			var message = tr.children('td:eq(2)').html();
			var mail = tr.children('input:eq(1)').val();
			var id_mess = tr.children('input:eq(0)').val();
			var tel = tr.children('input:eq(2)').val();

			if(tel == "") tel="NC";
			if(mail == "") mail="NC";
			$("#tb-mail-to-answer").attr('value', mail);
			$("#tb-id").attr('value', id_mess);
			
			$('#main-frbMessage-message-from').html('De : <span class="text-hight">'+from+' &lt'+mail+'&gt</span>');
			$('#main-frbMessage-message-tel').html('Téléphone: <span class="text-hight">'+tel+'</span>');
			$('#main-frbMessage-message-date').html('Le : <span class="text-hight">'+date+'</span>');
			$('#main-frbMessage-message-content p').html('<span class="text-hight">'+message+'</span>');
			
			$('#main-frbMessage-message').fadeIn('slow');

			var url = '<?php echo $data['baseurl']; ?>admin/frbMessage/frbMessage_MainController/readMessage';
			var id = tr.attr('id');
			var postData = tr.children('input').serialize();
			$.ajax({
				type : 'POST',
				url: url,
				cache: false,
				data: postData,
				success: function(html){
					tr.attr('class', 'click-to-view new-message-eq-0');
				}
			});
		});	
	});
});
</script>